package com.guohu.shadow;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.RectF;
import android.util.AttributeSet;
import android.view.View;

import androidx.annotation.Nullable;

public class TicketView extends View {
    public TicketView(Context context) {
        super(context);
        initTicket();
    }

    public TicketView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        initTicket();
    }

    public TicketView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        initTicket();

    }

    public TicketView(Context context, @Nullable AttributeSet attrs, int defStyleAttr, int defStyleRes) {
        super(context, attrs, defStyleAttr, defStyleRes);
        initTicket();

    }

    private Paint paint;
    private Path path;
    RectF rectF;

//    private final int height=10;
//    private int width=1080;
    private final int groovesWidth=20;
    private final int groovesHeight =22;
    private final int divider=10;


    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);

        int startX=0;

        int count=getWidth()/(divider+groovesWidth);

        int bw,bh,r,top,bottom;

        bw=groovesWidth;

        r=bw/2;

        bh=groovesHeight-r;

        bottom=groovesHeight;

        top=-(r-bh);


        for (int i=0;i<count;i++){

//            Path path=new Path();

            path.moveTo(startX,0);

            path.lineTo(startX,bh);

            path.lineTo(startX+groovesWidth,bh);

            path.lineTo(startX+groovesWidth,0);

            path.close();

            canvas.drawPath(path,paint);

            path.reset();


            rectF.left=startX;
            rectF.top=top;
            rectF.right=startX+groovesWidth;
            rectF.bottom=bottom;

            path.addArc(rectF,0,180);

            canvas.drawPath(path,paint);

            startX=startX+divider+groovesWidth;

        }

    }


    void initTicket(){
        createPaint();
        initPaint();
//        initInts();
        buildReactF();
        path=buildPath();
    }

    void createPaint(){
        paint=new Paint();
    }

    void initPaint(){
        paint.setStyle(Paint.Style.FILL);
        paint.setColor( Color.GRAY );
        paint.setStrokeWidth(1);//设置线宽
        paint.setAntiAlias(true);
    }

    void buildReactF(){
        rectF=new RectF();
    }

    private Path buildPath(){
        Path path=new Path();

        return path;
    }
    /**
     *
    Point a,b,c,d,e;
    float r,rd;


    private void initInts(){
        r=groovesWidth/2;
        rd= groovesHeight -r;

//        a=new Point(0,0);
//
//        b=new Point(r,r);
//
//        c=new Point(r, groovesHeight);
//
//        d=new Point(r+divider,groovesHeight);
//
//        e=new Point(r+divider,r);

        a=new Point(0,groovesHeight);
        b=new Point(divider,groovesHeight);
        c=new Point(divider,r);
        d=new Point(divider+r,0);
        e=new Point(divider+groovesWidth,r);
    }




    private class Point{
        public final float x;

        public final float y;

        public Point(float x, float y) {
            this.x = x;
            this.y = y;
        }
    }
     */

}
